<?php

namespace IDock\Insurance\HBIC\Response;

use IDock\Http\Response;
use IDock\IDock\IDockEnums;
use IDock\Insurance\HBIC\Response\AllHBICResponse;
use IDock\Insurance\HBIC\Response\CommonResponse;
use IDock\Insurance\HBIC\HBICEnums;
use IDock\Printer\VehicleModelPrinter;
use IDock\Printer\VehiclePrinter;

class VehicleModelResponse extends CommonResponse
{

    public $totalCount = 0;

    public function printerInit() :Response
    {
        $vehicleModelPrinter = new VehicleModelPrinter();
        $data = $this->getData();
        $this->totalCount = $data['PageTotal'] ?? 0;
        if(!isset($data['VehicleResponse']['Vehicle'][0])){
            $tmp = $data['VehicleResponse']['Vehicle'];
            unset($data['VehicleResponse']['Vehicle']);
            $data['VehicleResponse']['Vehicle'][] = $tmp;
            unset($tmp);
        }
        if(!empty($data['VehicleResponse']['Vehicle'])) foreach ($data['VehicleResponse']['Vehicle'] as $datum) {

            $vehiclePrinter = new VehiclePrinter();
            $vehiclePrinter->vehicleModelCode = $datum['VehicleCode'] ?? '';
            $vehiclePrinter->vehicleName = $datum['VehicleName'] ?? '';
            $vehiclePrinter->brandName = $datum['BrandName'] ?? '';
            $vehiclePrinter->vehicleExhaust = $datum['EXHAUSTSCALE'] ?? '';
            $vehiclePrinter->item['brandName'] = $datum['BrandName'] ?? '';

            if(is_array($datum['VehicleImport'])){
                $vehiclePrinter->vehicleImport = HBICEnums::$importFlag[$datum['VehicleImport'][0]];
            }else{
                $vehiclePrinter->vehicleImport = HBICEnums::$importFlag[$datum['VehicleImport'] ?? ''];
            }
            $vehiclePrinter->vehiclePrice = $datum['PurchasePrice'] ?? '';
            $vehiclePrinter->vehiclePriceWithOutTax = $datum['PurchasePriceTax'] ?? '';
            $vehiclePrinter->vehicleSeat = $datum['Seat'] ?? '';
            $vehiclePrinter->familyName = $datum['FamilyName'] ?? '';
            $vehiclePrinter->power = '';
            $vehiclePrinter->vehicleYear = $datum['YearPattern'] ?? '';
            $vehiclePrinter->vehicleTonnage = $datum['TonCount'] ?? '';
            $vehiclePrinter->wholeWeight = '';
            $vehiclePrinter->energyTypeCode = 'E01';
            if(!empty($datum['EnergyType'])){
                $energyTypeCode =  array_search($datum['EnergyType'],HBICEnums::$energyType);//新能源返回
                if($energyTypeCode){
                    $vehiclePrinter->energyTypeCode = $energyTypeCode;
                }
            }
            if(!empty($datum['EnergyType'])){
                $vehiclePrinter->isNewEnergy = '1';
            }

            $vehicleModelPrinter->setModelList($vehiclePrinter);
        }
        $this->printer = $vehicleModelPrinter;

        return $this;
    }
}
